package Client.View;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import Client.Model.GameModel;


/**
 * @author Rodrigo
 *
 */


@SuppressWarnings("serial")
public class LoginFrame extends JFrame implements Observer{

	public static final Color DEFAULT_BG_COLOR = new Color(17, 178, 233);
	public static final Color BG_COLOR_2 = new Color(136, 208, 232, 213);
	

	private Container cp;
    private GameModel model;
    private int height;
    private int width;
    GameFrame gframe = null;
    
	public LoginFrame(GameModel m) {
				
		  	super("NavalBattle Login"); 
	        
	        this.model = m;
	        this.height = 490;
	        this.width = 450;
	             
	        cp = getContentPane();
	        model.addObserver(this);
	 	        
	        setLocation(450, 120); 
	        setSize(width, height); 
	        
	        setMinimumSize(new Dimension(width,height));
	        setMaximumSize(new Dimension(width,height));
	        
	        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Terminate Application        
	        setVisible(true); 

	        setView();
	        
	        this.pack();
	        validate();
	        repaint();

	}


	@Override
	public void update(Observable o, Object arg) {

		if (model.getView()!=GameModel.VIEW_INITIAL){
			this.setVisible(false);
			if (gframe==null)
				gframe = new GameFrame(model, 600, 750);
		}
		else{
			if (gframe != null)
				gframe.setVisible(false);
			
			this.setVisible(true);
			this.revalidate();
			this.repaint();
		}
	}
	
	private void setView(){
		
		this.setBackground(DEFAULT_BG_COLOR);
		cp.setBackground(DEFAULT_BG_COLOR);
		cp.setLayout(null);
		
		JPanel panel;
		
		panel = new InitialView(model, height, width);
		panel.setVisible(true);
		cp.add(panel);	
		
		panel.setBounds(0,0,width,height);
		setResizable(false);
		
	}
	
	
}
